package com.potenza.wxuser.controller;

import com.potenza.wxuser.model.UserSocialInformation;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/c/drools")
public class DroolsController {

    @Autowired
    KieContainer kieContainer;

    @GetMapping("test")
    public Integer test(){
        // 业务对象
        UserSocialInformation userSocialInformation = new UserSocialInformation();
        userSocialInformation.setEducation("3");
        userSocialInformation.setHouseCertificate("1");
        KieSession kieSession = kieContainer.newKieSession();
        // 第四步 装入工作内存 Working Memory：工作内存，
        kieSession.insert(userSocialInformation);
        // 第五步：执行规则引擎
        kieSession.fireAllRules();

        kieSession.destroy();

        System.out.println("指定规则引擎后的结果：" + userSocialInformation.getTotalCreditScore());
        return userSocialInformation.getTotalCreditScore();
    }

}
